package com.vvv;

import com.vvv.method.ReentrantLockDemo01;

import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @author vvv
 * @date ${DATE} ${HOUR} ${MINUTE}
 * discription
 */
public class Main {
    public static void main(String[] args) throws Exception {
    }

    public static void test09() throws InterruptedException {
        ArrayList<String> list = new ArrayList<>();

    }

    public static void test08() {
        String s1 = new String("a") + new String("b");
        String s2 = s1.intern();
        String s = "ab";
        System.out.println(s == s1);
    }

    public void test06() {
        ExecutorService service = Executors.newSingleThreadExecutor();
        service.submit(() -> {
            Thread thread = Thread.currentThread();
            System.out.println(thread.getId());
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        service.shutdown();
    }
    public void test07() {
    }

    private static void test03() throws InterruptedException, ExecutionException {
        FutureTask<String> task = new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                System.out.println("hello ");
                return "world";
            }
        });
        Thread t1 = new Thread(task, "t1");

        t1.start();
        // 主线程会阻塞在这里，等待future返回结果
        String result = task.get();
        System.out.println(result);
    }

    public static void test01() {
        String s;
        LongAdder longAdder = new LongAdder();
        AtomicInteger atomicInteger = new AtomicInteger();
        atomicInteger.getAndIncrement();
        longAdder.increment();
    }


    public static void test02() {
        List<Integer> list = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        map.put("vvv", "value");
    }

    public static void test04() {
        ExecutorService executorService = Executors.newFixedThreadPool(2, new ThreadFactory() {
            private AtomicInteger at = new AtomicInteger(1);

            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "myThread" + at.getAndIncrement());
            }
        });
    }

    public static void test05() {
        ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
    }



}